﻿using PloobsEngine.SceneControl;
using PloobsEngine.Physics;
using PloobsEngine;
using PloobsEngine.Cameras;
using PloobsEngine.Input;
using Microsoft.Xna.Framework;
using PloobsEngine.Physics.Bepu;
using PloobsEngine.Modelo;
using PloobsEngine.Material;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine.Features;
using PloobsEngine.Commands;
using PloobsEngineDemo3;
using PloobsEngine.Light;

namespace Etapa1.Screens
{
    public class PostEffectsResearchScreen : SceneScreen
    {
        private BepuPhysicWorld physicWorld;
        private BrutalForceWorld mundo;
        private EngineStuff engine;        
        ICamera cam;

        public PostEffectsResearchScreen(EngineStuff es)
        {
            this.engine = es;
            physicWorld = new BepuPhysicWorld();
            mundo = new BrutalForceWorld(physicWorld);                        
            engine.Game.IsFixedTimeStep = true;
        }
        
        public override void LoadContent(EngineStuff es)
        {
            InputAdvanced inp = new InputAdvanced(engine);
            engine.AddComponent(inp);

            base.LoadContent(es);

            #region Models

            {
                TreeModel tm = new TreeModel("..\\Content\\Trees\\Pine");
                TreeShader ts = new TreeShader();
                ts.Initialize();
                TreeMaterial tmat = new TreeMaterial(ts);
                GhostObject go = new GhostObject(new Vector3(0, 0, 0), Matrix.Identity, new Vector3(0.05f));
                IObject ox = new SimpleObject(tmat, go, tm);
                mundo.AddObject(ox);
            }
            {
                TreeModel tm = new TreeModel("..\\Content\\Trees\\Rug");
                TreeShader ts = new TreeShader();
                ts.Initialize();
                TreeMaterial tmat = new TreeMaterial(ts);
                GhostObject go = new GhostObject(new Vector3(90, 0, 0), Matrix.Identity, new Vector3(0.05f));
                IObject ox = new SimpleObject(tmat, go, tm);
                mundo.AddObject(ox);
            }
            {
                TreeModel tm = new TreeModel("..\\Content\\Trees\\Pine");
                TreeShader ts = new TreeShader();
                ts.Initialize();
                TreeMaterial tmat = new TreeMaterial(ts);
                GhostObject go = new GhostObject(new Vector3(-90, 0, 0), Matrix.Identity, new Vector3(0.05f));
                IObject ox = new SimpleObject(tmat, go, tm);
                mundo.AddObject(ox);
            }
            #endregion

            cam = new CameraFirstPerson(true);
            cam.FarPlane = 2000;

            LightThrowBepu lt = new LightThrowBepu(mundo, engine);

            #region NormalLight
            DirectionalLight ld1 = new DirectionalLight(Vector3.Left, Color.White);
            DirectionalLight ld2 = new DirectionalLight(Vector3.Right, Color.White);
            DirectionalLight ld3 = new DirectionalLight(Vector3.Backward, Color.White);
            DirectionalLight ld4 = new DirectionalLight(Vector3.Forward, Color.White);
            DirectionalLight ld5 = new DirectionalLight(Vector3.Down, Color.White);
            float li = 0.4f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            mundo.AddLight(ld1);
            mundo.AddLight(ld2);
            mundo.AddLight(ld3);
            mundo.AddLight(ld4);
            mundo.AddLight(ld5);
            #endregion

            ////Criacao de uma Tecnica
            DeferredRenderTechnic dr = new DeferredRenderTechnic(engine);
            IRenderTechnic[] rt = new IRenderTechnic[] { dr };
            this.RenderTechnics = rt;
            mundo.AddCamera(cam);
            this.World = mundo;
            
            
            //DepthCueingPostEffect dcp = new DepthCueingPostEffect();
            //dr.AddPostEffect(dcp);

            HSVEffect pe = new HSVEffect(Vector4.Zero,new Vector4(1,1,1,1));
            dr.AddPostEffect(pe);


            Skybox sk = new Skybox(engine);
            engine.AddComponent(sk);

            SkyBoxUpdateParametersCommand su = new SkyBoxUpdateParametersCommand(cam, "..\\Content\\Textures\\Sky");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(su);


        }

    }
}

